<?php

namespace App\Containers\AppSection\Project\UI\API\Transformers;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Project\Models\Document;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class DocumentTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'files'
    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [

    ];

    public function transform(Document $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'label' => $t->label,
            'required' => $t->required,
        ];
    }

    public function includeFiles(Document $t): Collection
    {
        return $this->collection($t->files()->get(), new FileTransformer);
    }
}
